//
//  OilListTableView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/30.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "OilCardListTableView.h"
#import "OilCarStatusListHeadView.h"
#import "OilCarStatusListCell.h"
#import "OilCardListCell.h"

static CGFloat listHeadH = 115;

@interface OilCardListTableView ()

@property (nonatomic, strong) OilCarStatusListHeadView *headView;

@end

@implementation OilCardListTableView

- (OilCarStatusListHeadView *)headView {
  if (!_headView) {
    _headView = [[OilCarStatusListHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, listHeadH)];
    _headView.backgroundColor = [UIColor redColor];
  }
  return _headView;
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
  self = [super initWithFrame:frame style:style];
  if (self) {
    [self hideLine];
    [self hideTableFootView];
  }
  return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  if (section == 0) {
    return 3;
  } else {
    return 10;
  }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  if (indexPath.section == 0) {
    return 80;
  } else {
    return [OilCardListModel new].cellHeight;
  }
  
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  if (section == 0) {
    return 0;
  } else {
    return listHeadH;
  }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  if (section == 0) {
    return nil;
  } else {
    return self.headView;
  }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  
  if (indexPath.section == 0) {
    ///
    OilCarStatusListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OilCarStatusListCell"];
    if (!cell) {
      cell = [[OilCarStatusListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OilCarStatusListCell"];
    }
    [cell setupData:indexPath];
    return cell;
  }
  
  OilCardListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OilCardListCell"];
  if (!cell) {
    cell = [[OilCardListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OilCardListCell"];
  }
  cell.model = [OilCardListModel new];
  
  return cell;
  
}

@end
